﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;
using System.Windows.Documents;
using Eniux.Windows.ExtensionMethods;
namespace Eniux.Windows.ThreeDEngine.Adorners
{
    /// <summary>
    /// 当操作相机时，出现在3D视窗的装饰器
    /// </summary>
    public class TargetSymbolAdorner : Adorner
    {
        #region 构造、析构
        /// <summary>
        /// 默认构造函数
        /// </summary>
        /// <param name="adornedElement">要被添加装饰器的UIElement</param>
        /// <param name="position">位置</param>
        public TargetSymbolAdorner(UIElement adornedElement, Point position)
            : base(adornedElement)
        {
            Position = position;
        }

        #endregion

        #region 公共属性

        /// <summary>
        /// 获取或设置位置
        /// </summary>
        public Point Position { get; set; }

        #endregion

        #region 方法

        /// <summary>
        /// 绘制
        /// </summary>
        /// <param name="dc">绘制上下文</param>
        protected override void OnRender(DrawingContext dc)
        {
            var lightBrush = new SolidColorBrush(Colors.LightGray);
            var darkBrush = new SolidColorBrush(Colors.Gray);
            //lightBrush.Opacity = 0.4;
            //darkBrush.Opacity = 0.1;

            double t1 = 6; // thickness of dark circle pen
            double t2 = 2; // thickness of light pen (circle, arcs, segments)
            double d = 0; // distance from light circle to segments
            double l = 10; // length of segments
            double r = 20.0; // radius of light circle

            double r1 = r - (t1 + t2) / 2;
            double r2 = r + l;
            double r3 = r + t2 / 2 + d;
            double r4 = (r + r2) / 2;

            var darkPen = new Pen(darkBrush, t1);
            var lightPen = new Pen(lightBrush, t2);

            dc.DrawEllipse(null, lightPen, Position, r, r);
            dc.DrawEllipse(null, darkPen, Position, r1, r1);
            dc.DrawArc(null, lightPen, Position, 10, 80, r4, r4);
            dc.DrawArc(null, lightPen, Position, 100, 170, r4, r4);
            dc.DrawArc(null, lightPen, Position, 190, 260, r4, r4);
            dc.DrawArc(null, lightPen, Position, 280, 350, r4, r4);

            dc.DrawLine(
                lightPen,
                new Point(Position.X, Position.Y - r2),
                new Point(Position.X, Position.Y - r3));
            dc.DrawLine(
                lightPen,
                new Point(Position.X, Position.Y + r2),
                new Point(Position.X, Position.Y + r3));
            dc.DrawLine(
                lightPen,
                new Point(Position.X - r2, Position.Y),
                new Point(Position.X - r3, Position.Y));
            dc.DrawLine(
                lightPen,
                new Point(Position.X + r2, Position.Y),
                new Point(Position.X + r3, Position.Y));
        }

        #endregion
    }
}
